home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1279 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  857 b 

  1. Path: news.compuserve.com!newsmaster
  2. From: 100754.2730@compuserve.com (Martin Aupperle)
  3. Newsgroups: comp.lang.c++
  4. Subject: Q: Returning a reference
  5. Date: Wed, 10 Jan 1996 08:11:19 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4cvsm2$5ig@dub-news-svc-4.compuserve.com>
  8. NNTP-Posting-Host: dd67-016.compuserve.com
  9. X-Newsreader: Forte Free Agent v0.56
  10.  
  11. Borland C++ V4.5 does not allow to return a reference to a local
  12. variable:
  13.  
  14. int &doIt() {
  15.  
  16.   int i = 7;
  17.   return i;  // syntax error
  18.   }
  19.  
  20. I remember that I once had a compiler that did allow it (it gave me
  21. only a warning). 
  22. Which one is right? I think that it should be an error because after
  23. the function has terminated, the reference has no data object it is
  24. bound to any more.
  25.  
  26. Martin
  27.  
  28.  
  29. -----------------------------------
  30. Signatures are a waste of bandwidth
  31. -----------------------------------
  32.  
  33.